//! Start a UDP echo on an unused port.
//!
//! Test with
//! echo "hello zig" | nc -u localhost <port>
//!
// const builtin = @import("builtin");
const std = @import("std");
const upnp = @import("upnp.zig");

// const c = if (builtin.link_libc)
//     @cImport({
//         @cInclude("sys/socket.h");
//         @cInclude("netinet/in.h");
//         @cInclude("arpa/inet.h");
//     })
// else
//     void;

// export fn _start() void {
//     @call(.auto, main, .{}) catch unreachable;
// }

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    var device = upnp.Device{};
    try device.init(gpa.allocator(), "192.168.2.44");
    var server = try upnp.Server.init(gpa.allocator(), "192.168.2.44", &device);

    server.serve();
    server.deinit();
    device.deinit();
}

test "simple test" {
    var list = std.ArrayList(i32).init(std.testing.allocator);
    defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
    try list.append(42);
    try std.testing.expectEqual(@as(i32, 42), list.pop());
}
